<!DOCTYPE html>
<html>
	<head>
		<meta http-equiv="Expires" content="0">
		 <meta http-equiv="Pragma" content="no-cache">
		 <meta http-equiv="Cache-control" content="no-cache">
		 <meta http-equiv="Cache" content="no-cache">
		<meta charset="utf-8">
		<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
		<title>编带数据统计</title>
		<link rel="stylesheet" href="./layui/css/layui.css">
	</head>
	<body>
		<fieldset class="layui-elem-field site-demo-button">
			<legend><big><b>编带数据统计</b></big></legend>
			<div class="layui-fluid layui-form layui-form-pane">
				<div class="layui-row layui-form-item">
					<label class="layui-form-label">扫描二维码:</label>
					<div class="layui-input-block">
						<input class="layui-input" placeholder="请扫入特定的二维码" id="qr" type="text"/>
					</div>
				</div>
			</div>
		</fieldset>
		<fieldset class="layui-elem-field site-demo-button">
			<legend><big><b>当前信息</b></big></legend>
			<div id="DQ" class="layui-fluid layui-form layui-form-pane">
				<div class="layui-col-sm4">
						<label class="layui-form-label">光通量:</label>
						<div class="layui-input-block">
							<input class="layui-input" readonly=true placeholder="光通量" id="light_pass_number" type="text"/>
						</div>
				</div>
				<div class="layui-col-sm4">
					<label class="layui-form-label">电压:</label>
					<div class="layui-input-block">
						<input class="layui-input" readonly=true placeholder="电压" id="voltage" type="text"/>
					</div>
				</div>
				<div class="layui-row">
					
				</div>
				<div class="layui-col-sm4">
						<label class="layui-form-label">色区:</label>
						<div class="layui-input-block">
							<input class="layui-input" readonly=true placeholder="色区" id="color_area" type="text"/>
						</div>
				</div>
				<div class="layui-col-sm4">
					<label class="layui-form-label">bin_code:</label>
					<div class="layui-input-block">
						<input class="layui-input" readonly=true placeholder="bin_code" id="bin_code" type="text"/>
					</div>
				</div>
				
				<div class="layui-row">
					
				</div>
				<div class="layui-col-sm4">
					<label class="layui-form-label">显指:</label>
					<div class="layui-input-block">
						<input class="layui-input" readonly=true placeholder="显指" id="xianzhi" type="text"/>
					</div>
				</div>
				<div class="layui-col-sm4">
					<label class="layui-form-label">电流:</label>
					<div class="layui-input-block">
						<input class="layui-input" readonly=true placeholder="电流" id="dianliu" type="text"/>
					</div>
				</div>
				<div class="layui-row">
					<div class="layui-col-sm4">
						<label class="layui-form-label">流水码:</label>
						<div class="layui-input-block">
							<input class="layui-input" readonly=true placeholder="流水码" id="LSM" type="text"/>
						</div>
					</div>
					<div class="layui-col-sm4">
						<label class="layui-form-label">工单号:</label>
						<div class="layui-input-block">
							<input class="layui-input" readonly=true placeholder="工单号" id="order_id" type="text"/>
						</div>
					</div>
				</div>
				<div class="layui-row">
					<div class="layui-col-sm4">
						<label class="layui-form-label">产品型号:</label>
						<div class="layui-input-block">
							<input class="layui-input" readonly=true placeholder="产品型号" id="CPXH" type="text"/>
						</div>
					</div>
					<div class="layui-col-sm4">
						<label class="layui-form-label">数量:</label>
						<div class="layui-input-block">
							<input class="layui-input" readonly=true placeholder="数量" id="number" type="text"/>
						</div>
					</div>
				</div>
				
				<div class="layui-row">
					<div class="layui-col-sm4">
						<label class="layui-form-label">总投量:</label>
						<div class="layui-input-block">
							<input class="layui-input" readonly=true placeholder="总投量" id="allnumber" type="text"/>
						</div>
					</div>
					<div class="layui-col-sm4">
						<label class="layui-form-label">完成量:</label>
						<div class="layui-input-block">
							<input class="layui-input" readonly=true placeholder="完成量" id="finishnumber" type="text"/>
						</div>
					</div>
				</div>
				
				<div class="layui-row">
					
					<div class="layui-col-sm4">
						<label class="layui-form-label">时间:</label>
						<div class="layui-input-block">
							<input class="layui-input" readonly=true placeholder="时间" id="time" type="text"/>
						</div>
					</div>
				</div>
			</div>
		</fieldset>
		<fieldset class="layui-elem-field site-demo-button">
				<div class="layui-row">
					<div class="layui-form-item layui-form-text layui-col-sm8">
						<label class="layui-form-label ">修改数量</label>
						<div class="layui-input-block">
						  <textarea placeholder="请输入修改数量" class="layui-textarea" id="updatenumber"></textarea>
						</div>
						<div><button  class="layui-btn  layui-btn-radius layui-btn-normal " id="update">修改数量</button></div>
				
					</div>				
					
				</div>
				<hr  width="100%" style="height:1px;" color="#000000"/>
				
				<div  class="layui-btn-container" class="layui-row" id="button_box">
					
				</div>
			</div>
		</fieldset>
		<fieldset class="layui-elem-field site-demo-button">
			<legend><big><b>分光数据清单</b></big></legend>
			<div class="layui-fluid layui-form layui-form-pane">
				<div id="YC" class="layui-row"></div>
			</div>
		</fieldset>
		<!-- 加载类ui文件 -->
		<script src="./layui/layui.js"></script>
		<!-- 加载jQuery文件 -->
		<script src="./js/jquery.min.js"></script>
		<!-- 写脚本 -->
		<script>
			var id;
			//这里是扫描输入框的回车按下后执行的程式
			var FrontTwoString;
			layui.use(['layer','form','element'], function(){
					layer.msg('初始化正常!');
				});
			$("#qr").keypress(function(e){
				//如果按下的键值是回车键13就执行以下语句
				if(e.keyCode === 13){
					
					var qrc = $("#qr").val();
					record=qrc.split(" ");//
					$("#light_pass_number").val(record[0]+" "+record[1]);
					$("#voltage").val(record[2]+" "+record[3]);
					$("#color_area").val(record[4]);
					$("#bin_code").val(record[5]); 
					$("#xianzhi").val(record[6]+" "+record[7]);
					$("#dianliu").val(record[8]);
					$("#LSM").val(record[9]);
					$("#order_id").val(record[10]); 
					$("#CPXH").val(record[11]);
					$("#number").val(record[12]); 
					$("#time").val(GetDateStr(0));
						//localStorage.name = QRC;
						console.log();
						var patt1=/[A-Z]{1,2}\d+[A-Z]?\d+[A-Z]?-?[X|\d]?(?= T)/;//AK17B2681-2
						if(patt1.test(qrc)){//判断工单是否正常
							$.ajax({//
								type:'POST',
								url: "bpirecord.php",
								data:"&light_pass_number="+$("#light_pass_number").val()+"&voltage="+$("#voltage").val()+"&color_area="+$("#color_area").val()+"&bin_code="+$("#bin_code").val()+"&xianzhi="+$("#xianzhi").val()+"&dianliu="+$("#dianliu").val()+"&LSM="+$("#LSM").val()+"&order_id="+$("#order_id").val()+"&CPXH="+$("#CPXH").val()+"&number="+$("#number").val()+"&time="+$("#time").val(),
								dataType : "text",
								success: function(sss){
									$("#qr").val("").select();
									$("#qr").val("").select();
									datas=sss.split("-");
									id=datas[0];//存入的同时返回自增ID供给修改数量使用
									console.log(id);
									layer.msg(datas[3]);//返回信息);
									if(datas[3]=="存入成功"){
									console.log(parseInt($("#number").val()*1)+"-"+datas[2]);
										$("#allnumber").val(datas[1]);//获取工单号对应的投产量
										if(!isNaN(parseInt(datas[2]))){
											$("#finishnumber").val(parseInt(datas[2])*1);//获取完成量
										}
										if(isNaN(parseInt(datas[2]))){
											$("#finishnumber").val(parseInt($("#number").val()*1));//获取完成量
										}
									}
								}
							});
						}
						else{
							layer.msg('工单号输入有误'); 
						} 
				}
			});
	
	$("#update").click(function(){//修改当前数量
		$("#qr").select();//parseInt(myobj[0][j])
		var finishnumber=parseInt($("#finishnumber").val())-parseInt($("#number").val())+parseInt($("#updatenumber").val());//同步更新完成量
		$("#number").val($("#updatenumber").val());
		
		$("#finishnumber").val(finishnumber);
					$.ajax({
						type:"POST",
						url:"bpirecordupdate.php",
						data:"&id="+id+"&number="+$("#updatenumber").val()+"&finishnumber="+$("#finishnumber").val(),
						dataType:"text",
						success: function(data){
							layer.msg('修改成功');//返回信息);
							console.log(data);
						}
					});
				
	});
			function GetDateStr(AddDayCount) {//获取时间
				var dd = new Date();
				dd.setDate(dd.getDate()+AddDayCount);//获取AddDayCount天后的日期
				var y = dd.getFullYear();
				var m = dd.getMonth()+1;//获取当前月份的日期
				if(m<10){
					m="0"+m;
				}
				var d = dd.getDate();
				if(d<10){
					d="0"+d;
				}
				var hh = dd.getHours();  //获取当前小时数(0-23)
				if(hh<10){
					hh="0"+hh;
				}
				var min = dd.getMinutes();
				if(min<10){
					min="0"+min;
				}
				var ss = dd.getSeconds();
				if(ss<10){
					ss="0"+ss;
				}
				return y + "-" + m + "-" + d + " " + hh + ":" + min + ":" + ss;
			}
			function compareTime(startTime,endTime) {//时间的比较大小2018-04-24 14:59:16
			  var startTimes = startTime.substring(0, 10).split('-');
			  var endTimes = endTime.substring(0, 10).split('-');
			  startTime = startTimes[1] + '-' + startTimes[2] + '-' + startTimes[0] + ' ' + startTime.substring(10, 19);
			  endTime = endTimes[1] + '-' + endTimes[2] + '-' + endTimes[0] + ' ' + endTime.substring(10, 19);
			  console.log(startTime);
			  console.log(endTime);
			  var thisResult = (Date.parse(endTime) - Date.parse(startTime)) / 3600 / 1000;
			  console.log(thisResult);
			  if (thisResult < 0) {
				return  'exception';//结束时间小于开始时间
			  }
			  if (thisResult > 0) {
				return 'success';//结束时间大于开始时间
				//return '';
			  } 
			}
		</script>
	</body>
</html>